#include <iostream>
#include <algorithm>
#include <set>
using namespace std;

struct result{
	char *sch;
	double grasum;
	int peonum;
};
struct Rule{
	bool operator()(const result &a1,const result &a2){
		return a1.sch<a2.sch;
	}
};
void minstr(char*s){//
	while( s ){
		if( *s>='A'&&*s<='Z'){
			*s+=32;
		}
		s++;
	}
}
struct Rule1{
	bool operator()(const result &a1,const result &a2){
		if( a1.grasum!=a2.grasum ){ return a1.grasum>a2.grasum; }
		if( a1.peonum!=a2.peonum ){ return a1.peonum<a2.peonum; }
		return a1.sch<a2.sch;
	}
};


int main(){
	int n;
	double g;
	char *a,*s;
	cin>>n;
	set<result,Rule> r;
	set<result,Rule>::iterator p;
	result t;
	for( int i=0; i<n; i++ ){
		cin>>a>>g>>s;
		minstr(s);
		switch ( a[0] ){
			case 'B':g=g/1.5;break;
			case 'T':g=g*1.5;break;
		}
		t.sch=s;t.grasum=g;t.peonum=1;
		if( (p=r.find(t))!=r.end() ){
			g=p->grasum+g;t.peonum=p->peonum+1;
			r.erase(p);
			r.insert(t);
		}else{
			r.insert(t);
		}
	}
	sort(r.begin(),r.end(),Rule1());
	cout<<r.size()<<endl;int i;
	for( p=r.begin(),i=1; i<=r.size(); p++,i++ ){
		double up;
		int upc;
		if( i==1 ){
			printf("1 %s %.0f %d\n",p->sch,p->grasum,p->peonum);
			up=p->grasum;upc=1;
		}else{
			if( p->grasum==up ){
				printf("%d %s %.0f %d\n",upc,p->sch,p->grasum,p->peonum);
				up=p->grasum;upc=upc;
			}else{
				printf("%d %s %.0f %d\n",i,p->sch,p->grasum,p->peonum);
			}
		}
	}
	return 0;
}
